<script setup>
import {computed} from "vue";

const user = JSON.parse(sessionStorage.getItem("vue3_persistedstate"));
const system = user.system;
const permissions = system.usecases;

const props = defineProps({
  permission: {
    type: [String, Array],
  }
});
// console.log(permissions.includes(props.permission));
const showSlot = computed(() => {
  // 没有传入权限，直接显示
  if (!props.permission) {
    return true;
  }
  if (!permissions) {
    return false;
  }
  if (Array.isArray(props.permission)) {
    return props.permission.every(item => {
      permissions.includes(item);
    });
  } else {
    console.log(permissions.includes(props.permission));
    return permissions.includes(props.permission);
  }
});

</script>

<template>
  <slot v-if="showSlot" :userPermissions="permissions"></slot>
</template>

<style scoped lang="less">

</style>